// 导入路由实例

import router from './router'

import { getToken } from '@/utils/token'

// 不需要登录
const whiteList = ['/login', '/', '/layout', '/layout/home', '/search']
// 全局前置守卫
router.beforeEach((to, from, next) => {
  const token = getToken()
  if (token) {
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      // 带上想去的地址
      next(`/login?redirect=${to.path}`)
    }
  }
})
